<script charset="utf-8" src="/assets/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="/assets/kindeditor/lang/zh_CN.js"></script>
<script>
    KindEditor.ready(function(K) {

        window.editor = K.create('#news_body', {
            width : '900px',
            minWidth : '380px',
            height:'1000px',
            cssData : "body {font-size: 15px;}",
            items : [

                'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
                'flash', 'media', 'table', 'hr', 'pagebreak',
                'anchor', 'link', 'unlink', '|', 'about'
            ],
            afterCreate : function() {
                this.sync();
            },
            uploadJson : '/admins/news/upload_json',
            fileManagerJson : '../asp/file_manager_json.asp',
            allowFileManager : true,
            afterBlur: function(){
                this.sync();
            }//同步KindEditor的值到textarea文本框
        });
    });
</script>

<div class="page-header">
  <h1>新闻稿件编辑</h1>
</div>
<table class="edit_table">
<%= form_for [:admins, @news], method: @news.id ? 'put' : 'post',html: {class: "form-horizontal", role: "form",:multipart => true , :onsubmit => "return check()"} do |f| %>
  <input type="hidden" name="news[kind]" value="0"/>
  <input type="hidden" name="sec_value" id="sec_value" value=""/>
  
    <tr>
      <td>平台推送:</td>
      <td>
        <%i=0
          arr = [0,0,0]

          if params[:groups]
            p 1312312,params[:groups]
            params[:groups].each do |g|
              if g=='15'
                arr[0]=15
              end
              if g=='18'
                arr[1]=18
              end
              if g=='23'
                arr[2]=23
              end
            end
          end
          p 1312312,arr
        %>

        <% @groups.each do |group| %>
            <% if @news.groups.collect(&:id).include?(group.id) %>
                <input type="checkbox" name="groups[]" value="<%= group.id %>" checked />
            <% else %>
                <input type="checkbox" name="groups[]" value="<%= group.id %>" <%=(arr[i] == group.id ? "checked":"")%> />
            <% end %>
            <%= group.platform_name %>
            <%i+=1%>
        <% end %>
        (<%= must_label %>送审之后将不能再修改)

      </td>
    </tr>

  <tr>
    <td>是否要闻</td>
    <td><%= f.select :is_important_news,[['否',0],['是',1]] %></td>
  </tr>
  <tr>
    <td>新闻类别<%= must_label %></td>
    <td>
      <% if @news.category_id.blank? %>
        <%= f.select :category_id ,[['--请选择--',' ']] + @categories.collect{|cate| [cate.cataname,cate.id]} %>
        <span id="next_select"></span>
      <% elsif @news.category.parent.blank? %>
          <%= f.select :category_id ,[['--请选择--',' ']] + @categories.collect{|cate| [cate.cataname,cate.id]},:selected => @news.category_id %>
          <span id="next_select"></span>
      <% else %>
          <%= f.select :category_id ,[['--请选择--',' ']] + @categories.collect{|cate| [cate.cataname,cate.id]},:selected => @news.category.parent.id %>
          <span id="next_select">
            <%= select_tag :sec_cate_id,options_for_select(@news.category.parent.children.collect{|cate| [cate.cataname,cate.id]},@news.category_id) %>
          </span>
      <% end %>
    </td>
  </tr>
  <tr>
    <td>是否专题</td>
    <td>
      <span class="sptitle_span">点击选择专题</span> </br>
      <span id="choosed_sptitle" style="background-color: #66F4DF;"><%= @news.sptitles.collect(&:name).join(' || ') unless @news.sptitles.blank? %></span>
      <div class="myCloseButton"></div>
      <div id="sptitle_div" class="sptitle_div">
          <% @sptitles.each do |splitle| %>
            <% if @news.sptitles.collect(&:id).include?(splitle.id) %>
                <div><input type="checkbox" name="sptitles[]" value="<%= splitle.id %>" checked="checked" /><span id="sptitle<%= splitle.id %>" class="splitle_name"><%= splitle.name %></span></div>
            <% else %>
                <div><input type="checkbox" name="sptitles[]" value="<%= splitle.id %>" /><span id="sptitle<%= splitle.id %>" class="splitle_name"><%= splitle.name %></span></div>
            <% end %>
          <% end %>
      </div>
    </td>
  </tr>
  <tr>
    <td>新闻肩题</td>
    <td><%= f.text_field :uptitle, :class => 'long_input' %></td>
  </tr>
  <tr>
    <td>新闻标题<%= must_label %></td>
    <td><%= f.text_field :title, :class => 'long_input' %></td>
  </tr>
  <tr>
    <td>新闻副题</td>
    <td><%= f.text_field :bottomtitle, :class => 'long_input' %></td>
  </tr>
  <tr>
    <td>关键词</td>
    <td><%= f.text_field :keywords %> </br>
    <div style="color: #4298BA;">(注：多个关键词用“|”分隔。如：关键词1|关键词2)</div></td>
  </tr>
  <tr>
    <td>稿件作者<%= must_label %></td>
    <% if @news.writer %>
        <td><%= f.text_field :writer %></td>
    <% else %>
        <td><%= f.text_field :writer,:value => current_user.name %></td>
    <% end %>

  </tr>
  <tr>
    <td>摄影作者</td>
    <td><%= f.text_field :cameraman_name %><span style="color: #4298BA;">(<%= must_label %>如有照片请填写摄影师名称)</span></td>
  </tr>
  <tr>
    <td>联系电话<%= must_label %></td>
    <% if @news.phone %>
        <td><%= f.text_field :phone %></td>
    <% else %>
        <td><%= f.text_field :phone,:value => current_user.office_phone %></td>
    <% end %>
  </tr>
  <tr>
    <td>来稿单位<%= must_label %></td>
    <% if @news.contribution_units_id || !current_user.department %>
        <td><%= f.select :contribution_units_id ,[['--请选择--',' ']] + @departments.collect{|dep| [dep.name,dep.id]} %></td>
    <% else %>
        <td><%= f.select :contribution_units_id ,[['--请选择--',' ']] + @departments.collect{|dep| [dep.name,dep.id]},:selected => current_user.department.id %></td>
    <% end %>

  </tr>
  <% if current_user.admin? %>
      <tr>
        <td>首页图片</td>
        <td>
          <%= f.file_field :home_page_image %><%= f.hidden_field :home_page_image_cache %>
          <span style="color: #4298BA;">(图片尺寸:图说华理959*505,深度报道:169*169)</span>
        </td>
      </tr>
      <tr>
        <td>是否头条</td>
        <td><%= f.select :is_top, [['否',0],['是',1]] %></td>
      </tr>
      <tr>
        <td>头条标题</td>
        <td><%= f.text_field :yaowen_title, :class => 'long_input' %><span style="color: #4298BA;">(字数最好限制在21个字以内)</span></td>
      </tr>
      <tr>
        <td>头条内容</td>
        <td><%= f.text_area :toutiao_content,:size => '100x5' %><div style="color: #4298BA;">(字数最好限制在130个字以内)</div></td>
      </tr>
  <% end %>
  <tr>
    <td colspan="2">正文<%= must_label %><span style="color: #4298BA;">(图片(gif jpg jpeg png bmp,均小写).视频,音频(swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb mov mp4 mkv vob divx mpeg mpe aif acm asp au)大小不能超过30M)</span></td>
  </tr>
  <tr>
    <td colspan="2">
      <div class="col-sm-10">
        <%= f.text_area :body,value:@news.body , style: "font-size: 45" %>
      </div>
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center">
      <%= f.submit'确认',:class => 'btn btn-primary',:onclick => "getKind();" %>
      <%= link_to '返回',admins_news_index_path,:class => 'btn btn-info' %>
    </td>
  </tr>
<% end %>
</table>
<script type="text/javascript">
  var getKind = function getKind(){
      $("#sec_value").val($("#sec_cate_id").val());
   
  }
  function check(){				
				var ids = document.getElementsByName("groups[]");				
				var flag = false ;				
				for(var i=0;i<ids.length;i++){
					if(ids[i].checked){
						flag = true ;
						break ;
					}
				}
				if(!flag){
					alert("请最少选择一平台推送！");
					return false ;
				}
			}
  $(document).ready(getKind);
  $(document).on('page:load', getKind);
</script>
